package Operation;

import JavaBeans.*;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void operate(BookList bookList) {
        System.out.println("归还图书");
        if(bookList.getCurrentCount() == 0){
            System.out.println("当前书架为空！");
            return;
        }
        Scanner in = new Scanner(System.in);
        System.out.println("请输入您要归还的图书名：");
        String name = in.nextLine();
        for (int i = 0; i < bookList.getCurrentCount(); i++) {
            if(bookList.getBook(i).getName().equals(name)){
                if(bookList.getBook(i).getState() == State.TAKEN){
                    bookList.getBook(i).setState(State.AVAILABLE);
                    System.out.println("归还成功!");
                }else{
                    System.out.println("此书已在书架中，不用归还。");
                }
                return;
            }
        }
        System.out.println("此书不属于本书架，无法归还!");
    }
}
